package com.bijiawang.user.service;

import com.bijiawang.user.bean.Userinfo;
import com.bijiawang.user.mapper.UserinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserinfoService {

    @Autowired
    private UserinfoMapper userinfoMapper;


    public Userinfo getUserinfoByPhoneNumber(String phoneNumber) {
        Userinfo userinfo = null;
        userinfo = userinfoMapper.findByPhoneNumber(phoneNumber);
        return userinfo;
    }


    public Userinfo getUserinfoByUserName(String username) {
        Userinfo userinfo = null;
        userinfo = userinfoMapper.findByUsername(username);
        return userinfo;
    }

    public void addUser(Userinfo userinfo) {
        userinfoMapper.addnew(userinfo);
    }

    public String returnUsername(String username){
        return userinfoMapper.queryByUsername(username);
    }

    public String returnPhonenumber(String phonenumber){
        return userinfoMapper.queryByPhonenumber(phonenumber);
    }

    public void updatepasw(String number,String pasw){
        userinfoMapper.changepasw(number,pasw);
    }

    public void updateUsername(String oldUsername,String newUsername){
        userinfoMapper.changeUsername(oldUsername,newUsername);
    }

    public void updatePhoneNumber(String oldPhoneNumber,String newPhoneNumber){
        userinfoMapper.changePhoneNumber(oldPhoneNumber,newPhoneNumber);
    }

    public String returnEmail(String email){
        return userinfoMapper.queryByEmail(email);
    }

    public void updateEmail(String email,String username){
        userinfoMapper.changeEmail(email,username);
    }

}